package cn.ranko.run;

import cn.ranko.framework.utils.ClassUtil;
import org.springframework.web.bind.annotation.RequestMapping;

import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.List;

/**
 * Created by ZJ08 on 2016/8/18.
 */
public class AnnotationsSearch {

    public static void main(String[] args) throws ClassNotFoundException {
        List<Class<?>> classes = ClassUtil.getClasses("cn.ranko.api.action");
        for (Class clas : classes) {
            Annotation[] annotations = clas.getAnnotations();
            for (Annotation annotation : annotations) {
                if (annotation instanceof RequestMapping) {
                    RequestMapping anno_RequestMapping = (RequestMapping) annotation;
                    System.out.println("类名：" + clas.getName()+"，请求地址："+anno_RequestMapping.value()[0]);
                    Method[] methods = clas.getDeclaredMethods();
                    for (Method method : methods) {
                        boolean hasRequestMappings = method.isAnnotationPresent(RequestMapping.class);
                        RequestMapping requestMapping = method.getAnnotation(RequestMapping.class);
                        System.out.println("方法名："+method.getName()+"，方法描述："+requestMapping.name());
                        System.out.println("请求地址："+requestMapping.value()[0]+"，请求类型："+requestMapping.method()[0]);
                        if(method.getParameterTypes().length>0){
                            Class<?>[] methodClass = method.getParameterTypes();
                            System.out.println("请求参数：");
                            for(int i=0;i<methodClass.length;i++){
                                System.out.println(methodClass[i].getName());
                            }
                        }else{
                            System.out.println("请求参数：无");
                        }
                        System.out.println("返回类型："+method.getReturnType().getName());
                    }
                }
            }
            System.out.println("-------------------------------------------------------------------------");
        }
    }

}
